﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using log4net;

namespace RollBack.src.ui.ExplorerView
{
    class RestoreData : ExplorerData
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(RestoreData));
        public string m_restoreDir
        {
            set;
            get;
        }

        public RestoreData( )
        {
            this.m_leftData = new RestoreData.LeftPanelData();
            this.m_rightData = new RestoreData.RightPanelData();
            this.m_rightData.m_itemsChecked = true;
        }

        public new class LeftPanelData : ExplorerData.LeftPanelData
        {
            public LeftPanelData()
            {
                m_allowDrag = true;
                m_allowDrop = true;
            }

            protected override void expandRoot(object data,ExplorerData edata)
            {
                RestoreData rvdata = (RestoreData)edata;
                if (rvdata != null)
                {
                    string rootValue = rvdata.m_restoreDir;
                    if (rootValue != null)
                    {
                        TreeNode curr = (TreeNode)data;
                        curr.Nodes.Clear();
                        this.expandDir(curr,rvdata,rootValue);
                    }
                }
            }

            protected override void expandDir(TreeNode curr,ExplorerData edata, string startDir)
            {
                RestoreData rvdata = (RestoreData)edata;
                if (rvdata != null)
                {
                    string sdir = rvdata.m_restoreDir;
                    if (curr.FullPath.Length >= rvdata.RootDisplayNodePath.Length)
                    {
                        sdir = rvdata.m_restoreDir + "\\" +  curr.FullPath.Substring(rvdata.RootDisplayNodePath.Length);
                    }
                    base.expandDir(curr,rvdata, sdir);
                }
            }
        }

        public new class RightPanelData : ExplorerData.RightPanelData
        {
            public RightPanelData()
            {
                m_allowDrag = true;
                m_allowDrop = false;
                m_itemsChecked = true;
                m_checkBoxes = true;
            }

            public override List<ListViewItem> expandNode(ExplorerData edata, string dir,bool checkAll)
            {
                List<ListViewItem> list = new List<ListViewItem>();
                RestoreData rvdata = (RestoreData)edata;
                if (rvdata != null)
                {
                    string sdir = rvdata.m_restoreDir +"\\" + dir;
                    list = base.expandNode(edata, sdir,checkAll);
                }
                return list;
            }

            public override string getPathOnDisk(ExplorerData edata)
            {
                string dir = "";
                RestoreData rvdata = (RestoreData)edata;
                if (rvdata != null)
                {
                    dir = rvdata.m_restoreDir + "\\";
                }
                return dir;
            }
        }

    }
}
